package com.lagou.test;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBUtil {
    private String dbUrl="jdbc:mysql://localhost:3306/lagou?useSSL=false&serverTimezone=UTC";
    private String dbUserName="root";
    private String dbPassword="820521";
    private String jdbcName="com.mysql.cj.jdbc.Driver";

    public Connection getCon() throws Exception{
        Class.forName(jdbcName);
        Connection con= DriverManager.getConnection(dbUrl,dbUserName,dbPassword);
        return con;
    }

    public void closeCon(Connection con) throws Exception{
        if(con!=null){
            ((Connection) con).close();
        }
    }

    public static void main(String[] args) {
        DBUtil dbUtil=new DBUtil();
        try {
            dbUtil.getCon();
            System.out.println("测试连接成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
